package com.zty.netty;

import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;

/**
 * @Author ZTY
 * @Description 自定义默认watcher
 * @Date 12:58 2023-12-07
 **/

public class MyWatcher implements Watcher {

    @Override
    public void process(WatchedEvent event) {
        //  判断事件类型  连接类型的事件？
        if (event.getType() == Event.EventType.None){
            if (event.getState() == Event.KeeperState.SyncConnected){
                System.out.println("Zookeeper连接成功");
            }else if (event.getState() == Event.KeeperState.AuthFailed){
                System.out.println("Zookeeper认证失败");
            } else if (event.getState() == Event.KeeperState.Disconnected) {
                System.out.println("zookeeper断开连接");
            }
        } else if (event.getType() == Event.EventType.NodeCreated) {
            System.out.println(event.getPath() + "节点已创建");
        } else if (event.getType() == Event.EventType.NodeDeleted) {
            System.out.println(event.getPath() + "节点已删除");
        } else if (event.getType() == Event.EventType.NodeDataChanged) {
            System.out.println(event.getPath() + "节点数据已修改");
        } else if (event.getType() == Event.EventType.NodeChildrenChanged) {
            System.out.println(event.getPath() + "子节点发生了变化");
        }
    }
}
